/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.geftu.model;


import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import java.util.Collection;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import javax.xml.bind.annotation.XmlTransient;
import br.com.geftu.util.SwingColumn;
import javax.swing.table.DefaultTableCellRenderer;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;




/**
 *
 * @author jorgenei
 */
@Entity
@Table(name = "tb_categoriadefeito", catalog = "bddefeitos", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Categoria.findAll", query = "SELECT t FROM Categoria t"),
    @NamedQuery(name = "Categoria.findByIdcat", query = "SELECT t FROM Categoria t WHERE t.idcat = :idcat"),
    @NamedQuery(name = "Categoria.findByCategoria", query = "SELECT t FROM Categoria t WHERE t.categoria = :categoria")})
public class Categoria implements java.io.Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "categoriaerro")
    private Collection<Solucao> SolucaoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "categoriaerro")
    private Collection<Relato> RelatoCollection;
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name="idcat", sequenceName="categoria_seq", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="idcat")
    @Basic(optional = false)
    @SwingColumn(description="The Id",renderer=DefaultTableCellRenderer.class,colorOfBackgound="")
    private Integer idcat;
    @NotNull(message = "O campo não pode ser nulo")
    @NotEmpty(message = "O campo não pode estar em branco")
    @Size(min = 4, max = 20, message = "O campo dever possuir entre 4 e 20 caracteres")
    @SwingColumn(description="Categoria",renderer=DefaultTableCellRenderer.class,colorOfBackgound="")
    private String categoria;

    public Categoria() {
    }
    
    public Categoria(Integer idcat) {
        this.idcat = idcat;
    }
    
      public Categoria(Integer idcat, String categoria) {
        this.idcat = idcat;
        this.categoria = categoria;
    }
    
    public Categoria(String categoria){
        this.categoria = categoria;
    }

    public Integer getIdcat() {
        return idcat;
    }

    public void setIdcat(Integer idcat) {
        Integer oldIdcat = this.idcat;
        this.idcat = idcat;
        changeSupport.firePropertyChange("idcat", oldIdcat, idcat);
    }

    public String getCategoria() {
        return categoria;
    }

    public void setCategoria(String categoria) {
        String oldCategoria = this.categoria;
        this.categoria = categoria;
        changeSupport.firePropertyChange("categoria", oldCategoria, categoria);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idcat != null ? idcat.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Categoria)) {
            return false;
        }
        Categoria other = (Categoria) object;
        if ((this.idcat == null && other.idcat != null) || (this.idcat != null && !this.idcat.equals(other.idcat))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return categoria;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

    @XmlTransient
    public Collection<Solucao> getSolucaoCollection() {
        return SolucaoCollection;
    }

    public void setSolucaoCollection(Collection<Solucao> SolucaoCollection) {
        this.SolucaoCollection = SolucaoCollection;
    }

    @XmlTransient
    public Collection<Relato> getRelatoCollection() {
        return RelatoCollection;
    }

    public void setRelatoCollection(Collection<Relato> RelatoCollection) {
        this.RelatoCollection = RelatoCollection;
    }
    
}
